﻿using BLL;
using DAL;
using DevExpress.XtraBars.Docking2010.Views.Widget;
using Model;
using NPOI.SS.Formula.Functions;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tools;
using 后整理管理系统.自定义类;
using 纺织贸易管理系统.其他窗体;
using 纺织贸易管理系统.新增窗体;
using 纺织贸易管理系统.设置窗体;
using 纺织贸易管理系统.选择窗体;

namespace 纺织贸易管理系统.报表窗体
{
    public partial class 来货退仓单 : Form
    {
        public DanjuTable  danju { get; set; }
        private string State = string.Empty;
        private List<danjumingxitable > danjumingxitables = new List<danjumingxitable >();
        private List<JuanHaoTable> juanList = new List<JuanHaoTable>();
        public List<StockTable> stockTables = new List<StockTable>();
        public List<JuanHaoTable> InitJuans = new List<JuanHaoTable>();//可以传入的卷
        public FormUseful Useful { get; set; }
        public List<ManualCode> manualCodes = new List<ManualCode>();

        private int rowindex = 0;
        private StockHelper stockHelper;
      
        public 来货退仓单()
        {
            InitializeComponent();
            dateEdit1.DateTime = DateTime.Now;
            CreateGrid.Create(this.Name, gridView1);
            CreateGrid.Create("销售发货单", gridView2);
            try
            {
                gridView1.Columns["Bianhao"].ColumnEdit = ButtonEdit1;
                gridView1.Columns["pingming"].ColumnEdit = ButtonEdit1;
                gridView1.Columns["danwei"].ColumnEdit = cmddanwei;
                gridView1.Columns["yanse"].ColumnEdit = colorbtn;
                gridView1.Columns["ColorNum"].ColumnEdit = colorbtn;
                gridView1.IndicatorWidth = 30;
                cmbMadanYangshi.Text = SettingService.GetSetting(new Setting() { formname = this.Name, settingname = "码单样式", settingValue = "" }).settingValue;
            }
            catch
            {
                配置列ToolStripMenuItem_Click(null, null);
            }
        }

        private void 来货入库单_Load(object sender, EventArgs e)
        {
            stockHelper = new StockHelper()
            {
                txtkehu = txtkehu,
                juanList = juanList,
                RollgridControl = gridControl2,
                DetailgridControl = gridControl1,
                MinxiGridview = gridView1,
                RollsGridview = gridView2,
                danjumingxitables = danjumingxitables,
                dateEdit1 = dateEdit1,
                txtdanhao = txtdanhao,
                stocks = stockTables
            };
            Init();
        }
        private void Init()
        {
            if (Useful == FormUseful.新增)
            {
                danju = new DanjuTable();
                txtdanhao.Text = BianhaoBLL.CreatDanhao(FirstLetter.生产退卷单, dateEdit1.DateTime, DanjuLeiXing.退卷单);
                txtkehu.Text = "";
                danjumingxitables.Clear();
                manualCodes.Clear();
                for (int i = 0; i < 30; i++)
                {
                    danjumingxitables.Add(new danjumingxitable() { danwei = "米" });
                    manualCodes.Add(new ManualCode() { DocNum = txtdanhao.Text });
                }
                txtckmc.Text = string.Empty;
                txtbeizhu.Text = string.Empty;
                gridControl1.DataSource = danjumingxitables;
                gridControl1.RefreshDataSource();
                juanList.Clear();
                gridControl2.DataSource = juanList;
                gridControl2.RefreshDataSource();
                gridControl5.DataSource = manualCodes;
                gridControl5.RefreshDataSource();
                if (InitJuans.Count > 0)
                {
                  stockHelper.CreateDanjuWithJuanhaotable(new SelectParms() { Danju = danju, Juanhaos = InitJuans, StockTables = stockTables, Txtckmc = txtckmc, Txtkehu = txtkehu});//根据细码生成出库单
                }
                else
                {
                    //如果传入的卷不为空的时候就是按卷生成发货单
                    if (stockTables.Count > 0)
                    {
                       new StockHelper() { danjumingxitables=danjumingxitables}. CreateDanjuWithDanjumingxi(new SelectParms() { Danju=danju,StockTables=stockTables,Juanhaos= InitJuans, Txtckmc=txtckmc,Txtkehu=txtkehu });//从入库单信息直接生成出库单
                    }
                }
               
            }
            else
            {
                txtdanhao.Text = danju.dh;
                txtkehu.Text = danju.ksmc;
                dateEdit1.DateTime = danju.rq;
                txtckmc.Text = danju.ckmc;
                txtbeizhu.Text = danju.bz;
                danjumingxitables = danjumingxitableService.Getdanjumingxitablelst(x => x.danhao == danju.dh);
                for (int i = danjumingxitables.Count; i < 30; i++)
                {
                    danjumingxitables.Add(new danjumingxitable() { danwei = "米" });
                }
                //加载原料信息
                manualCodes = Connect.dbcontext.Queryable<ManualCode>().Where(x => x.DocNum == danju.dh).ToList();
                for (int i = 0; i < 50 - manualCodes.Count; i++)
                {
                    manualCodes.Add(new ManualCode() { DocNum = txtdanhao.Text });
                }
                gridControl5.DataSource = manualCodes;
                gridControl1.DataSource = danjumingxitables;
                gridControl1.RefreshDataSource();
            }
           
        }
        private void 新增ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                gridView1 .CloseEditForm ();
                if (danjumingxitables.Where(x =>!string.IsNullOrWhiteSpace( x.pingming )).ToList().Count == 0)
                {
                    Sunny.UI.UIMessageBox.ShowError("保存失败！没有任何布料！如果有布料品名必须要填写!");
                    return;
                }
                if (string.IsNullOrWhiteSpace(txtkehu.Text))
                {
                    Sunny.UI.UIMessageBox.ShowError("保存失败！请选择客户");
                    return;
                }
                if (string.IsNullOrWhiteSpace(txtbeizhu.Text))
                {
                    Sunny.UI.UIMessageBox.ShowError("保存失败！请填写退仓原因");
                    return;
                }
                danju.bz = txtbeizhu.Text;
                danju.ksmc  = txtkehu.Text;
                danju.dh = txtdanhao.Text;
                danju.djlx = DanjuLeiXing.退卷单 ;
                danju.rq = dateEdit1.DateTime.Date ;
                danju.ckmc = txtckmc.Text;
                danju.StockName = cmbcunfang.Text;
                danju.totaljuanshu = danjumingxitables.Sum(x => x.chengpingjuanshu);
                danju.TotalMishu = danjumingxitables.Sum(x => x.chengpingmishu);
                danju.zhuangtai = "未审核";
                danju.wuliugongsi = txtWuliuInfo.Text;
                danju.shouhuodizhi = txtShouhuodizhi.Text;
                danju.own = Tools.CurrentUser.user.YHBH;
                Connect.dbcontext.BeginTran();
               
                if (Useful == FormUseful.新增)
                {
                    来货退卷单BLL .保存(danju, danjumingxitables, SelectHelper.CreatJuanhao (gridView2 ));
                }
                else
                {
                    来货退卷单BLL.修改单据 (danju, danjumingxitables, SelectHelper.CreatJuanhao(gridView2));
                }
                ///保存手工码单

                Connect.dbcontext.Deleteable<ManualCode>().Where(x => x.DocNum == txtdanhao.Text).ExecuteCommand();
                Connect.dbcontext.Insertable<ManualCode>(manualCodes.Where(x => x.Col1 > 0).ToList()).ExecuteCommand();
                Connect.dbcontext.CommitTran();
                AlterDlg.Show("保存成功");
                if (ShowMessageBox.ShowAskBox("是否继续新增操作？") == DialogResult.Yes)
                {
                    Useful = FormUseful.新增;
                    //清空所有控件
                    Init();
                }
                else
                {
                    MainForm.mainform.CloseTab();
                }
            }
            catch(Exception ex)
            {
                Connect.dbcontext.RollbackTran();
                ShowMessageBox.ShowErrorBox (  "保存单据的时候发生了错误" + ex.Message);
                
            }
          
        }


        private void 复制行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rowindex = gridView1.FocusedRowHandle;
        }

        private void 粘贴行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CopyRow.Copy<danjumingxitable>(danjumingxitables, rowindex, gridView1, gridView1.FocusedRowHandle, this);
        }

        private void 删除行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gridView1.DeleteRow(gridView1.FocusedRowHandle);
        }

        private void 添加行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            danjumingxitables.Add(new danjumingxitable() { danhao = txtdanhao.Text, rq = dateEdit1.DateTime  });
            gridControl1.RefreshDataSource();
        }

        private void 配置列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var fm = new 配置列(gridView1) { formname = this.Name, Obj = new danjumingxitable() };
            fm.ShowDialog();
        }

        private void 保存样式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateGrid.SaveGridview(this.Name, gridView1);
        }

        private void txtckmc_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var fm = new 仓库选择();
            fm.ShowDialog();
            txtckmc.Text = fm.stock.mingcheng;
        }
        private void 选择布料()
        {
            if (txtckmc.Text == "")
            {
                MessageBox.Show("请先选择仓库名称", "错误", MessageBoxButtons.OK);
                return;
            }
            var fm = new 库存选择() { StockName = txtckmc.Text,CustomerName=txtkehu.Text  };
            fm.ShowDialog();
            if (fm.pingzhong.Count > 0)
            {
                var stockhelper = new StockHelper() { DetailgridControl = gridControl1, MinxiGridview = gridView1, txtdanhao = txtdanhao, dateEdit1 = dateEdit1, stocks = fm.pingzhong, danjumingxitables = danjumingxitables, txtkehu = new DevExpress.XtraEditors.ButtonEdit() { Text = txtkehu.Text  } };
                SelectHelper.StockConverToDanjumingxi(gridView1, fm.pingzhong , danjumingxitables, txtdanhao.Text, dateEdit1.DateTime, DanjuLeiXing.退卷单);
                stockhelper.加载卷(juanList, gridControl2, txtckmc.Text);
                fm.Dispose();
                gridControl1.RefreshDataSource();
                gridView1.CloseEditor();
            }
        }
        private void ButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            选择布料();
        }

        private void 打印预览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InitDanju();
            new Tools.打印退卷单()
            {
                danjuTable = danju,
                danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrEmpty( x.pingming) ).ToList(),
                danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                mingxiinfo = new Tools.FormInfo() { FormName = this.Name, GridviewName = gridView1.Name }
            }.Print(PrintPath.报表模板 + "退卷单.frx", PrintModel.Privew);
        }
        private void InitDanju()
        {
            danju.bz = txtbeizhu.Text;        
            danju.ckmc = txtckmc.Text;
            danju.StockName = cmbcunfang.Text;
            danju.dh = txtdanhao.Text;
            danju.djlx = DanjuLeiXing.退卷单; 
            danju.Hanshui = IsHanshuiModel.含税;
            danju.je = danjumingxitables.Sum(x => x.hanshuiheji) + danjumingxitables.Sum(x => x.weishuiheji);
            danju.totaljuanshu = danjumingxitables.Sum(x => x.chengpingjuanshu);
            danju.TotalMishu = danjumingxitables.Sum(x => x.chengpingmishu);       
            danju.own = Tools.CurrentUser.user.YHBH;
            danju.ksmc = txtkehu.Text;
            danju.shouhuodizhi = txtShouhuodizhi.Text;
            danju.rq = dateEdit1.DateTime.Date;
            danju.wuliugongsi = txtWuliuInfo.Text;
        }

        private void 打印编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (后整理管理系统.自定义类.PrintService.CheckPrintDesignAccess())
            {
                InitDanju();
                new Tools.打印退卷单()
                {
                    danjuTable = danju,
                    danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrEmpty(x.pingming )).ToList(),
                    danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                    mingxiinfo = new Tools.FormInfo() { FormName = this.Name, GridviewName = gridView1.Name }
                }.Print(PrintPath.报表模板 + "退卷单.frx", PrintModel.Design);
            }
        }

        private void 直接打印ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InitDanju();
            new Tools.打印退卷单()
            {
                danjuTable = danju,
                danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrEmpty(x.pingming)).ToList(),
                danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                mingxiinfo = new Tools.FormInfo() { FormName = this.Name, GridviewName = gridView1.Name }
            }.Print(PrintPath.报表模板 + "退卷单.frx", PrintModel.Print );
        }

        private void gridView2_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            stockHelper.SelectionChange(gridView2);
        }

        private void 码单编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (PrintService.CheckPrintDesignAccess())
            {
                PrintMadan(PrintModel.Design);
            }
        }
        private void PrintMadan(PrintModel printsytle)
        {
            InitDanju();
            var Yidabaolist = SelectHelper.CreatJuanhao(gridView2);
            try
            {

                switch (cmbMadanYangshi.Text)
                {
                    case "竖版样式":
                        new Tools.打印成品码单()
                        {
                            danjuTable = danju,
                            danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrWhiteSpace(x.pingming)).ToList(),
                            danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                            juanHaoTables = SelectHelper.CreatJuanhao(gridView2),
                        mingxiinfo = new Tools.FormInfo() { FormName = "销售发货单", GridviewName = gridView1.Name }
                        }.Print(PrintPath.报表模板 + "\\madan.frx", printsytle);
                        break;
                    case "清单码单":
                        new Tools.打印清单码单()
                        {
                            danjuTable = danju,
                            danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrWhiteSpace(x.pingming)).ToList(),
                            danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                            juanHaoTables = SelectHelper.CreatJuanhao(gridView2),
                            mingxiinfo = new Tools.FormInfo() { FormName = "销售发货单", GridviewName = gridView1.Name },
                            JuanInfo = new Tools.FormInfo { FormName = "打卷报表", GridviewName = gridView2.Name }
                        }.Print(PrintPath.报表模板 + "\\清单码单.frx", printsytle);
                        break;
                    case "横版样式":
                        if (Yidabaolist.Count > 0)
                        {
                            new Tools.打印横版码单()
                            {
                                danju = danju,
                                juanhaolist = Yidabaolist,
                                formInfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = "gridView1" },
                                danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrWhiteSpace(x.pingming)).ToList(),
                                mingxiinfo = new Tools.FormInfo() { FormName = "销售发货单", GridviewName = gridView1.Name }
                            }.打印(printsytle, PrintPath.报表模板 + "\\A4纸.frx");
                        }
                        else
                        {
                            MessageBox.Show("没有任何包装信息！打印失败", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        break;
                    case "横版款号":
                        if (Yidabaolist.Count > 0)
                        {
                            new Tools.打印横版码单()
                            {
                                danju = danju,
                                juanhaolist = Yidabaolist,
                                formInfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = "gridView1" },
                                danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrWhiteSpace(x.pingming)).ToList(),
                                mingxiinfo = new Tools.FormInfo() { FormName = "销售发货单", GridviewName = gridView1.Name }
                            }.打印(printsytle, PrintPath.报表模板 + "\\横版款号.frx");
                        }
                        else
                        {
                            MessageBox.Show("没有任何包装信息！打印失败", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    case "包装样式":
                        if (Yidabaolist.Count > 0)
                        {
                            new Tools.打印包装码单() { danju = danju, juanhaolist = Yidabaolist, formInfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = "gridView1" } }.打印(printsytle, PrintPath.报表模板 + "\\打包码单.frx");
                        }
                        else
                        {
                            MessageBox.Show("没有任何包装信息！打印失败", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    case "手工码单":
                      
                        new Tools.打印手工码单()
                        {
                            danju = danju,
                            juanhaolist = manualCodes,
                            formInfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = "gridView1" },
                            danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrWhiteSpace(x.pingming)).ToList(),
                            mingxiinfo = new Tools.FormInfo() { FormName = this.Name, GridviewName = gridView1.Name }
                        }.Print(PrintPath.报表模板 + "\\手工码单.frx", printsytle);
                        break;
                    case "A支架":
                        InitDanju();
                        new Tools.打印退卷单()
                        {
                            danjuTable = danju,
                            danjumingxitables = danjumingxitables.Where(x => !string.IsNullOrEmpty(x.pingming)).ToList(),
                            danjuinfo = new Tools.FormInfo() { FormName = "销售发货单查询", GridviewName = gridView1.Name },
                            mingxiinfo = new Tools.FormInfo() { FormName = this.Name, GridviewName = gridView1.Name }
                        }.Print(PrintPath.报表模板 + "退卷单.frx", PrintModel.Design);
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (string.IsNullOrWhiteSpace(danju.IsPrinter))
            {
                State = "单据已打印1次";
            }
            else
            {
                State = "单据已打印" + (danju.IsPrinter.Substring(5, danju.IsPrinter.Length - 6).TryToInt() + 1).ToString() + "次";
            }
            PrintState();
            if (Sunny.UI.UIMessageBox.ShowAsk("该单据已打印！是否立即保存该单据"))
            {
                新增ToolStripMenuItem_Click(null, null);
            }
        }
        /// <summary>
        /// 标识该单据已打印
        /// </summary>
        private void PrintState()
        {
            DanjuTableService.UpdateDanjuTable($"IsPrinter='{State }'", x => x.dh == txtdanhao.Text);
        }

        private void 码单预览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrintMadan(PrintModel.Privew);
        }

        private void 直接打印ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            PrintMadan(PrintModel.Print);
        }

        private void txtkehu_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            SelectHelper.SelectCustomer(new SelectParms() { Danju = danju, Txtkehu = txtkehu });
        }

        private void gridView5_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                for (int col = 1; col < 11; col++)
                {
                    if (gridView5.FocusedColumn.FieldName == "Col" + col.ToString())
                    {
                        decimal sumcol = 0;
                        for (var c = 1; c < 11; c++)
                        {
                            sumcol += (decimal)gridView5.GetRowCellValue(gridView5.FocusedRowHandle, "Col" + c.ToString());
                        }
                        manualCodes[gridView5.FocusedRowHandle].SumCol = sumcol;
                    }
                }
                if (gridView5.FocusedColumn.FieldName == "Lot")
                {
                    var lot = gridView5.GetRowCellValue(gridView5.FocusedRowHandle, "Lot").ToString();
                    var mingxi = danjumingxitables.FirstOrDefault(x => x.ganghao == lot);
                    if (mingxi != null)
                    {
                        if (!string.IsNullOrWhiteSpace(mingxi.pingming))
                        {
                            manualCodes[gridView5.FocusedRowHandle].Color = mingxi.yanse;
                            manualCodes[gridView5.FocusedRowHandle].ItemNo = mingxi.kuanhao;
                            manualCodes[gridView5.FocusedRowHandle].FlowerPattern = mingxi.Huahao;
                        }
                    }
                }
                手输码单刷新();
            }
            catch (Exception ex)
            {
                ShowMessageBox.ShowErrorBox("计算的时候发生了错误：" + ex.Message);
            }
        }
        private void 手输码单计算单据明细(danjumingxitable mingxi, decimal length)
        {
            mingxi.chengpingjuanshu++;
            mingxi.chengpingmishu += length;
        }
        private void 手输码单刷新()
        {
            for (var row = 0; row < manualCodes.Count; row++)
            {
                if (string.IsNullOrWhiteSpace(manualCodes[0].Color))
                {
                    break;
                }
                else
                {

                    if (row == 0)
                    {
                        var mingxi = danjumingxitables.FirstOrDefault(x => x.ganghao == manualCodes[row].Lot && x.yanse == manualCodes[row].Color);
                        if (mingxi != null)
                        {
                            mingxi.chengpingjuanshu = 0;
                            mingxi.chengpingmishu = 0;
                            if (!string.IsNullOrWhiteSpace(mingxi.pingming))
                            {
                                for (var col = 1; col < 11; col++)
                                {
                                    if ((decimal)gridView5.GetRowCellValue(row, "Col" + col.ToString()) > 0)
                                    {
                                        手输码单计算单据明细(mingxi, (decimal)gridView5.GetRowCellValue(row, "Col" + col.ToString()));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (manualCodes[row].Col1 > 0)
                        {
                            if (string.IsNullOrWhiteSpace(manualCodes[row].Lot))
                            {
                                manualCodes[row].Color = manualCodes[row - 1].Color;
                                manualCodes[row].ItemNo = manualCodes[row - 1].ItemNo;
                                manualCodes[row].Lot = manualCodes[row - 1].Lot;
                                manualCodes[row].FlowerPattern = manualCodes[row - 1].FlowerPattern;
                            }
                            else
                            {
                                if (manualCodes[row].Lot != manualCodes[row - 1].Lot || manualCodes[row].Color != manualCodes[row - 1].Color)
                                {
                                    var m = danjumingxitables.FirstOrDefault(x => x.ganghao == manualCodes[row].Lot && x.yanse == manualCodes[row].Color);
                                    if (m != null)
                                    {
                                        m.chengpingjuanshu = 0;
                                        m.chengpingmishu = 0;
                                    }
                                }
                            }
                            var mingxi = danjumingxitables.FirstOrDefault(x => x.ganghao == manualCodes[row].Lot && x.yanse == manualCodes[row].Color);
                            if (mingxi != null)
                            {
                                for (var col = 1; col < 11; col++)
                                {
                                    if ((decimal)gridView5.GetRowCellValue(row, "Col" + col.ToString()) > 0)
                                    {
                                        手输码单计算单据明细(mingxi, (decimal)gridView5.GetRowCellValue(row, "Col" + col.ToString()));
                                    }
                                }
                            }
                        }
                    }
                }
                gridControl1.RefreshDataSource();
                gridControl5.RefreshDataSource();
            }
        }

        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            danjumingxitables[gridView1.FocusedRowHandle].toupimishu = danjumingxitables[gridView1.FocusedRowHandle].chengpingmishu;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SettingService.Update(new Setting() { formname = this.Name, settingname = "码单样式", settingValue = cmbMadanYangshi.Text });
                MessageBox.Show("设置默认码单成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置默认码单失败！原因是" + ex.Message);
            }
        }
    }
}
